// 链表的逆序
function revertList(head) {
    if (!head || !head.next) return this;
    let next = head.next;
    let pretemp = revertList(head.next);
    head.next = null;
    next.next = head;
    return pretemp;
}

// 链表的逆序mn
function revertList2(head, m, n) {
    let dumy = ListNode(0);
    dumy.next = head;

    let temp = dumy;
    for (let i = 0; i < m - 1; i++) {
        temp = temp.next;
    }

    let pre = null;
    let cur = temp.next;
    for (let i = 0; i < n - m; i++) {
        let next = cur.next;
        temp.next = pre;
        pre = cur;
        cur = next;
    }
    temp.next.next = cur;
    temp.next = pre;
    return dumy.next
}
// 判断链表的焦点
function hascylcel(head) {
    while (head) {
        head.tag = true;
        head = head.next;
    }
    while (head) {
        if (head.tag) return true;
        head = head.next;
    }
    return false
}
// 判断是否有环
function hascylcel2(head) {
    while (head) {
        if (head.tag) return true;
        head.tag = true;
        head = head.next;
    }
    return false
}
// 链表的划分
function split(head, m) {
    let dumy = new ListNode(0);
    dumy.next = head;

    let pre = dumy;
    let cur = dumy.next;
    let ishas = 0;
    let arr = [];
    while (cur) {
        if (cur.val == m || cur.val > m) {
            pre.next = cur.next
            cur.next = null;
            arr.push(cur)
            ishas = 1
        }
        if(ishas){
            cur = pre.next
            ishas = 0;
        }else {
            cur = cur.next;
            pre = pre.next
        }
    }
    while(arr.length){
        pre.next = arr.shift()
        pre = pre.next
    }
    return dumy.next
}

// 链表的归并？不太理解
function contain(l1,l2){
    if(l1 == null){
        return l2
    }
    if(l2 == null){
        return l1
    }
    if(l1.val < l2.val){
        l1.next = contain(l1.next, l2);
        return l1
    }else {
       l2.next = contain(l1,l2.next);
       return l2
    }
}